#ifndef _TAXIHANDLER_H
#define _TAXIHANDLER_H

struct TaxiPathPrototype
{
	ui32 id;
	ui32 from;
	ui32 to;
	ui32 price;
};

struct TaxiPathNodePrototype
{
	ui32 id;
	ui32 path;
	ui32 seq;
	ui32 mapid;
	float x;
	float y;
	float z;
	ui32 flags;
	ui32 waittime;
};

struct TaxiNode
{
	ui32 id;
	ui32 mapid;
	float  x;
	float  y;
	float  z;
	ui32 horde_mount;
	ui32 alliance_mount;
};

struct TaxiPathNode
{
	float x, y, z;
	ui32 mapid;
};

class TaxiPath
{
	friend class TaxiHandler;
	set<TaxiPathNode*> m_nodes;
	ui32 price;
	TaxiPathNode* m_firstnode;
	bool m_first;
	bool m_calculated; // WTF? woher kommen die denn? oO
	ui32 m_taxitime;
	ui32 from, to;
	ui32 id;
public:
	TaxiPath() : m_first(true), m_calculated(false), m_taxitime(0) {}
	void AddPathNode(TaxiPathNode* nd);
	TaxiPathNode* GetFirstPathNode();
	ui32 GetPathId() { return id; }
	ui32 GetPrice() { return price; }
	ui32 GetDuration(bool lastnode = true);
	set<TaxiPathNode*>::iterator GetNodesBegin() { return m_nodes.begin(); }
	set<TaxiPathNode*>::iterator GetNodesEnd() { return m_nodes.end(); }
	void UpdatePosition(Player* plr, ui32 diffsincestart);
	ui32 GetNodeCount() { return m_nodes.size(); }
};

class TaxiHandler : public Single<TaxiHandler>
{
	DBCStore<TaxiPathPrototype> dbcTaxiPath;
	DBCStore<TaxiPathNodePrototype> dbcTaxiPathNode;
	DBCStore<TaxiNode> dbcTaxiNode;
	bool m_loaded;
	bool m_load;
	map<ui32, TaxiPath*> m_taxipathes;
	map<ui32, TaxiNode*> m_taxinodes;
public:
	TaxiHandler() : m_loaded(false), m_load(false)
	{
	}
	void LoadDbc();
	void LoadPathes();
	TaxiNode* GetNextNode(float x, float y, float z, ui32 mapid);
	TaxiNode* GetNodeById(ui32 nodeid) { return m_taxinodes[nodeid]; }
	TaxiPath* GetTaxiPath(ui32 id) { return m_taxipathes[id]; }
	TaxiPath* GetTaxiPath(ui32 firstnode, ui32 endnode);
	void SetTaximask(ui32* mask);

};

#define sTaxiHandler (*TaxiHandler::getSingle())

#endif